package PTA_05_29;

import java.text.SimpleDateFormat;
import java.util.*;

public class Main1{
    public static void main(String[] args) {
        Scanner in=new Scanner(System.in);
        int num=in.nextInt();
        Student1[] studentArray = new Student1[num];
        for(int i=0;i<num;i++)
        {
            String name=in.next();
            int year=in.nextInt();
            int month=in.nextInt();
            int day=in.nextInt();
            String studentId=in.next();
            String school=in.next();
            studentArray[i]=new Student1(name,year,month,day,studentId,school);
        }

        Arrays.sort(studentArray);
        for(Student1 s:studentArray)
            System.out.println(s);
    }
}
class Student1 implements Comparable{
    private String name;
    private Date birthday;
    private String studentId;
    private String school;

    public Student1(String name, int year, int month, int day, String studentId, String school) {
        this.name = name;
        Calendar cal = Calendar.getInstance();
        cal.set(year, month - 1, day); // month需要减1，因为Calendar的月份从0开始
        this.birthday = cal.getTime();
        this.studentId = studentId;
        this.school = school;
    }

    SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");

    @Override
    public int compareTo(Object o) {
        Student1 other = (Student1) o;
        return this.studentId.compareTo(other.studentId);
    }

    @Override
    public String toString() {
        return "Student[" +
                "name=" + name + "," +
                " birthday=" + sdf.format(birthday) +
                ", studentId=" + studentId +
                ", school=" + school + ']';
    }

    @Override
    public boolean equals(Object obj) {
        if (this == obj)
            return true;
        if (obj == null || getClass() != obj.getClass())
            return false;
        Student1 student = (Student1) obj;
        return Objects.equals(name, student.name) &&
                Objects.equals(birthday, student.birthday) &&
                Objects.equals(studentId, student.studentId) &&
                Objects.equals(school, student.school);
    }

    @Override
    public int hashCode() {
        return Objects.hash(name, birthday, studentId, school);
    }
}